{% extends 'base.html' %}
{% block title %}
    <title>{{ title }}</title>
{% endblock %}
{% block content %}
    <div class="layui-card">
        <div class="layui-card-header">设置我的资料</div>
        <div class="layui-card-body" pad15="">
            <form class="layui-form">

                <div class="layui-form-item">
                    <label class="layui-form-label">我的角色</label>
                    <div class="layui-input-block">
                        <div class="layui-input-inline">
                            <input type="hidden" name="level_id" value="{{ level_id }}">
                            <input type="text" name="role" value="{% if level_id == 0 %}超级管理员{% elif level_id == 1 %}管理员{% elif level_id == 2 %}访客{% endif %}"
                                   readonly=""
                                   class="layui-input">
                        </div>
                        <div class="layui-form-mid layui-word-aux">不可修改</div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">用户名</label>
                    <div class="layui-input-inline">
                        <input type="text" name="username" value="{{ username }}" readonly="" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">不可修改</div>
                </div>
                <input type="hidden" name="dir_id" value="{{ dir_id }}">
                {% if level_id != 0 %}
                    <div class="layui-form-item">
                        <label class="layui-form-label">部门</label>
                        <div class="layui-input-inline">
                            <input type="text" name="dir_name" value="{{ dir_name }}" readonly="" class="layui-input">
                        </div>
                        <div class="layui-form-mid layui-word-aux">不可修改</div>
                    </div>
                {% endif %}
                <div class="layui-form-item">
                    <label class="layui-form-label">手机</label>
                    <div class="layui-input-inline">
                        <input type="text" name="telephone" value="{{ telephone }}" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="" lay-filter="setmyinfo">确认修改</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
{% endblock %}
{% block customjs %}
    <script src="/static/js/set_csrf_async.js"></script>
    <script>
        layui.use('form', function () {
            var layer = layui.layer;
            var form = layui.form;

            // 监听修改用户信息表单提交
            form.on('submit(setmyinfo)', function (data) {
                $.ajax({
                        type: 'put',
                        url: '/user/center/',
                        data: data.field,
                        dataType: 'json',
                        success: function (data) {
                            if (data.code === 0) {
                                layer.msg(data.msg, {
                                    icon: 6, time: 2000, end: function () {
                                        location.href = '/user/center/'
                                    }
                                });
                            } else {
                                layer.msg('Failed:' + data.msg, {
                                    icon: 6, time: 2000, end: function () {
                                        return
                                    }
                                });
                            }
                        }
                    }
                );
                return false;
            });
        })
        ;
    </script>
{% endblock %}